<style>
</style>
<template>
  <list_url ref="list_url" :config="config">
    <template #action="{row}">
      <el-button @click="to_edit(row)" size="small">详情</el-button>
    </template>
  </list_url>
</template>
<script>
import {iframe, in_right_admin} from "@/js/tool.js";
import {ajax} from "@/js/api_tool.js";
import {_config} from "@/js/s94_tool.js";
import s94Mjs from "s94-js";

export default {
  props: ['__iframe'],
  data(){
    let app = this, btns = {}, is_del = this.$get('is_del');

    if(in_right_admin('SharingReceiver/sync_wechat')) btns['同步到微信支付'] = function(){
      ajax({url:"/admin/sharing_receiver/sync_wechat", loading:true});
    }
    if(in_right_admin('SharingReceiver/add')) btns['添加'] = function(){ iframe('sharing_receiver/edit') }
    if(in_right_admin('SharingReceiver/delete')) btns['彻底删除'] = function(){ app.$refs['list_url'].delete() }
    let pay_type_map = _config('status_alias_map.order_pay.pay_type');
    pay_type_map["wechat_partner"] = "微信服务商";
    let relation_type_map = {
      'SERVICE_PROVIDER': '服务商',
      'STORE': '门店',
      'STAFF': '员工',
      'STORE_OWNER': '店主',
      'PARTNER': '合作伙伴',
      'HEADQUARTER': '总部',
      'BRAND': '品牌方',
      'DISTRIBUTOR': '分销商',
      'USER': '用户',
      'SUPPLIER': '供应商',
    }
    let forms_config = {};
    let list_cols = {
      id: {name:'id', label:'ID', width:'65px', fixed:'left', type: 'hidden'},
      pay_type:{name:'pay_type', label:'支付类型',type:'select_one', config: pay_type_map},
      name:{name:'name', label:'商户名称'},
      account:{name:'account', label:'账号', width:'120px'},
      relation_type:{name:'relation_type', label:'与分账方关系',type:'select_one', config: relation_type_map},
    };
    if (is_del){
      list_cols['delete_time'] = {name:'delete_time', label:'删除时间', width:'165px', type:'datetime'};
    }else {
      list_cols['create_time'] = {name:'create_time', label:'创建时间', width:'165px'};
    }
    if (!_config('this_tenant.id')){
      list_cols['tenant_id'] = {name:'tenant_id', label:'租户', width:'65px', fixed:'right'};
    }
    list_cols['action'] = {name:'action', label:'操作', width:'80px', type:'action', fixed:'right'};

    return {
      config: {
        api: '/admin/sharing_receiver/'+(is_del?'recycle':'list'),
        title: "分账接收方列表"+(is_del?'(已删除)':''),
        btns: btns,
        forms_config: forms_config,
        list_cols: list_cols,
        resdata: function(list){
          return list;
        },
        limit: 20,
        p: this.$get('p', 1),
      },
    }
  },
  methods: {
    to_edit(row){
      let can_edit = in_right_admin('SharingReceiver/edit') && ~[0,row.tenant_id].indexOf(_config('this_tenant.id'))
      let param = {
        id: row.id,
      }
      if (!can_edit) param['is_info'] = 1;
      iframe('sharing_receiver/edit?'+s94Mjs.param_encode(param))
    },
  },
  mounted() {
    let app = this;
    if (!this.__iframe) window['app'] = this;
  }
}
</script>
